home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / mac / Reviewed⁄Demos / Spearhead Demo / demota / pak1.pk3 / anim / runto_cover.scr < prev    next >
Encoding:
Text File  |  2002-10-21  |  4.4 KB  |  158 lines

  1.  
  2. //=================================================
  3. //=================================================
  4. start:
  5.     //Println "Running runto_cover.scr with move dir" self.movedir
  6.     //waitexec anim/default_inithandler.scr
  7.     //waitexec anim/smoking.scr::SmokeRemoveCigarette
  8.     
  9.     //***Hey Boon, I'll skip the dive for cover behavior for now 'till you fix it.
  10.     while (1)
  11.     {
  12.         waitexec anim/runto_inopen.scr
  13.     }
  14.  
  15.     self weaponcommand mainhand attachtohand mainhand
  16.     
  17.     // This toggles debug printing on and off for this script.
  18.     group.debug = 0
  19.     thread DPrintln "Entering runto_cover.scr"
  20.  
  21.     group.rundistance = 140
  22.     group.divedistance = 238.4
  23.  
  24.     thread PlayRunAnimation
  25.     group.runAnimationThread = parm.previousthread
  26.  
  27.     local.dived = waitthread MonitorForDive
  28.     
  29.     if (local.dived)
  30.     {
  31.         end    // If we dived, we're done.
  32.     }
  33.  
  34.     pause    // This thread isn't actually meant to terminate if he's running.  If local.dived == 0, then he's running.
  35. end
  36.  
  37.  
  38. //=================================================
  39. // PlayRunAnimation calls a standard running script with a waitexec.  It's done from a seperate thread like this to 
  40. // keep all threads in the same threadgroup, so that they will all end together if the group is terminated.
  41. PlayRunAnimation:
  42.     waitexec anim/runto_inopen.scr
  43. end
  44.  
  45. //=================================================
  46. // MonitorForDive watches the distance remaining and tries to find a good time to play an ending animation such as a 
  47. // dive.
  48. MonitorForDive:
  49.  
  50.     // Abort if we're so close we'll never be able to dive
  51.     if ( (self.pathdist < group.divedistance) && (self.pathdist < group.rundistance) )
  52.     {
  53.         thread DPrintln "Distance of " self.pathdist " is too small, no diving for me."
  54.         end 0
  55.     }
  56.  
  57.  
  58.     // Now wait until we have a straight run for the target
  59.     thread DPrint "Waiting to get a straight run."
  60.     while(!self.hascompletelookahead)
  61.     {
  62.         thread DPrint "."
  63.         wait 0.25    // This number is fairly arbitrary, I just didn't want to check every single frame.
  64.     }
  65.     thread DPrintln
  66.  
  67.     // Now decide what we want to do at the end
  68.     thread DPrintln "I have a straight run, deciding what to do next."
  69.     waitframe
  70.     if ( ( self.pathdist > (300 + randomint 300) ) || ( self.pathdist < group.divedistance && self.pathdist > group.rundistance ) )
  71.     {
  72.         thread DPrintln "Distance of " self.pathdist ".  Decided to run/crouch."
  73.         local.endAnim = ( self.weapongroup + "_standtocrouch_run" )
  74.         local.endDist = group.rundistance
  75.     }
  76.     else if ( self.pathdist > group.divedistance )
  77.     {
  78.         thread DPrintln "Distance of " self.pathdist ".  Decided to dive."
  79.         local.endAnim = ( self.weapongroup + "_standtocrouch_dive" )
  80.         local.endDist = group.divedistance
  81.     }
  82.     else
  83.     {
  84.         thread DPrintln "Distance of " self.pathdist " is too small, no diving for me."
  85.         end 0
  86.     }
  87.  
  88.  
  89.     // Now wait for my moment
  90.     local.speed = vector_length( self.velocity )
  91.     thread DPrint "Waiting for a good distance"
  92.     while ( self.pathdist > (local.endDist + 0.25*local.speed) )
  93.     {
  94.         thread DPrint "."
  95.         wait 0.25    // 0.25 seconds, to correspond with the 0.25*local.speed in the if check.
  96.         local.speed = vector_length( self.velocity )
  97.     }
  98.     thread DPrintln
  99.     thread DPrint "Almost got the right distance"
  100.     while ( self.pathdist > local.endDist )
  101.     {
  102.         thread DPrint "."
  103.         waitframe
  104.         // Assume that velocity won't change much in these few frames
  105.     }
  106.     thread DPrintln
  107.  
  108.     thread DPrintln "Geronimo!"
  109.     group.runAnimationThread end
  110.  
  111.     self setMotionAnim local.endAnim
  112.     self waittill flaggedanimdone
  113.     self.position = crouch
  114.  
  115. end 1
  116.  
  117.  
  118.  
  119. //=================================================
  120. // thread DPrintln - for debug prints
  121. DPrintln local.text1 local.text2 local.text3 local.text4 local.text5:
  122.     thread DPrintorPrintln 1 local.text1 local.text2 local.text3 local.text4 local.text5
  123. end
  124.  
  125. DPrint local.text1 local.text2 local.text3 local.text4 local.text5:
  126.     thread DPrintorPrintln 0 local.text1 local.text2 local.text3 local.text4 local.text5
  127. end
  128.  
  129. DPrintorPrintln local.newline local.text1 local.text2 local.text3 local.text4 local.text5:
  130.     if (group.debug == 1)
  131.     {
  132.         if (local.text1 != NIL)
  133.         {
  134.             print local.text1
  135.             if (local.text2 != NIL)
  136.             {
  137.                 print local.text2
  138.                 if (local.text3 != NIL)
  139.                 {
  140.                     print local.text3
  141.                     if (local.text4 != NIL)
  142.                     {
  143.                         print local.text4
  144.                         if (local.text5 != NIL)
  145.                         {
  146.                             print local.text5
  147.                         }
  148.                     }
  149.                 }
  150.             }
  151.         }
  152.         if (local.newline == 1)
  153.         {
  154.             println
  155.         }
  156.     }
  157. end
  158.